<template>
	<view class="container home-bg home-h home-pd">
		<view v-if="user" class="user-container">
			<image class="picture" src="/src/static/images/picture.png" mode=""></image>
			<view class="name">{{user.nickname}}</view>
			<view class="number">{{user.username}}</view>
		</view>
		<view v-if="centralWarehouse" class="menu-container">
			<view v-for="item in menList" class="menu-item flex flex-items-center">
				<image class="warehouse" :src="`/src/static/images/${item.src}`" mode=""></image>
				<view class="name flex-1">{{item.name}}</view>
				<uv-icon name="arrow-right"></uv-icon>
			</view>
		</view>
		<view v-if="user" @click="out" class="OutButton flex flex-justify-center flex-items-center">
			退出登录
		</view>
	</view>
</template>

<script setup>
	import { storeToRefs } from 'pinia';
	import {
		useAccountStore
	} from '@/store';
	import {
		onLoad,
		onReachBottom,
		onPullDownRefresh,
		onShow
	} from '@dcloudio/uni-app';
	const RelId = ref(uni.getStorageSync('Rel-Id'));
	const accountStore = useAccountStore();
	const { user,centralWarehouse } = storeToRefs(accountStore);
	const menList = ref([{
		name: "",
		src: 'warehouse.png'
	}]);
	onLoad(()=>{   
		if(centralWarehouse.value.userRelRespVOList.length&&user.value){
			let userRelRespVOList =  centralWarehouse.value.userRelRespVOList;
			menList.value[0].name = (userRelRespVOList.find(i=>i.id==RelId.value)||{relName:""}).relName;
		}
	});
	function init(){
		
	}
	function out(){
	uni.showModal({
		title: '提示',
		content: '确认退出登录',
		success: function (res) {
			if (res.confirm) {
				 accountStore.loginOut().then(res=>{
				 	uni.showToast({
				 		title:'操作成功',
				 		icon:'none'
				 	})
				 	setTimeout(()=>{
				 		uni.reLaunch({
				 			url:'/pages/login/index'
				 		})
				 	},1000)
				 })
			} else if (res.cancel) {
				 
			}
		}
	});
		
	}
</script>

<style scoped lang="scss">
	@import "index.scss";
</style>